<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="所属商户" prop="merchantId">
        <el-input
          v-model="queryParams.merchantId"
          placeholder="请输入所属商户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="店铺名称" prop="NAME">
        <el-input
          v-model="queryParams.NAME"
          placeholder="请输入店铺名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="店铺二维码" prop="qrCode">
        <el-input
          v-model="queryParams.qrCode"
          placeholder="请输入店铺二维码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="店铺LOGO" prop="LOGO">
        <el-input
          v-model="queryParams.LOGO"
          placeholder="请输入店铺LOGO"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否默认" prop="isDefault">
        <el-input
          v-model="queryParams.isDefault"
          placeholder="请输入是否默认"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人姓名" prop="CONTACT">
        <el-input
          v-model="queryParams.CONTACT"
          placeholder="请输入联系人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信支付商户号" prop="wxMchId">
        <el-input
          v-model="queryParams.wxMchId"
          placeholder="请输入微信支付商户号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信支付APIv2密钥" prop="wxApiV2">
        <el-input
          v-model="queryParams.wxApiV2"
          placeholder="请输入微信支付APIv2密钥"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信支付证书" prop="wxCertPath">
        <el-input
          v-model="queryParams.wxCertPath"
          placeholder="请输入微信支付证书"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="支付宝appId" prop="alipayAppId">
        <el-input
          v-model="queryParams.alipayAppId"
          placeholder="请输入支付宝appId"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="联系电话" prop="PHONE">
        <el-input
          v-model="queryParams.PHONE"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="ADDRESS">
        <el-input
          v-model="queryParams.ADDRESS"
          placeholder="请输入地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经度" prop="LATITUDE">
        <el-input
          v-model="queryParams.LATITUDE"
          placeholder="请输入经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="维度" prop="LONGITUDE">
        <el-input
          v-model="queryParams.LONGITUDE"
          placeholder="请输入维度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="距离" prop="DISTANCE">
        <el-input
          v-model="queryParams.DISTANCE"
          placeholder="请输入距离"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="营业时间" prop="HOURS">
        <el-input
          v-model="queryParams.HOURS"
          placeholder="请输入营业时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="营业执照" prop="LICENSE">
        <el-input
          v-model="queryParams.LICENSE"
          placeholder="请输入营业执照"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统一社会信用码" prop="creditCode">
        <el-input
          v-model="queryParams.creditCode"
          placeholder="请输入统一社会信用码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行名称" prop="bankName">
        <el-input
          v-model="queryParams.bankName"
          placeholder="请输入银行名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行卡账户名" prop="bankCardName">
        <el-input
          v-model="queryParams.bankCardName"
          placeholder="请输入银行卡账户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行卡卡号" prop="bankCardNo">
        <el-input
          v-model="queryParams.bankCardNo"
          placeholder="请输入银行卡卡号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="最后操作人" prop="OPERATOR">
        <el-input
          v-model="queryParams.OPERATOR"
          placeholder="请输入最后操作人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['backendApi:store:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['backendApi:store:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['backendApi:store:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['backendApi:store:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="storeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="自增ID" align="center" prop="ID" /> -->
      <!-- <el-table-column label="所属商户" align="center" prop="merchantId" /> -->
      <el-table-column label="店铺名称" align="center" prop="NAME" />
      <!-- <el-table-column label="店铺二维码" align="center" prop="qrCode" />
      <el-table-column label="店铺LOGO" align="center" prop="LOGO" />
      <el-table-column label="是否默认" align="center" prop="isDefault" /> -->
      <el-table-column label="联系人姓名" align="center" prop="CONTACT" />
      <!-- <el-table-column label="微信支付商户号" align="center" prop="wxMchId" />
      <el-table-column label="微信支付APIv2密钥" align="center" prop="wxApiV2" />
      <el-table-column label="微信支付证书" align="center" prop="wxCertPath" />
      <el-table-column label="支付宝appId" align="center" prop="alipayAppId" />
      <el-table-column label="支付宝应用私钥" align="center" prop="alipayPrivateKey" />
      <el-table-column label="支付宝应用公钥" align="center" prop="alipayPublicKey" /> -->
      <el-table-column label="联系电话" align="center" prop="PHONE" />
      <el-table-column label="地址" align="center" prop="ADDRESS" />
      <!-- <el-table-column label="经度" align="center" prop="LATITUDE" />
      <el-table-column label="维度" align="center" prop="LONGITUDE" />
      <el-table-column label="距离" align="center" prop="DISTANCE" /> -->
      <el-table-column label="营业时间" align="center" prop="HOURS" />
      <!-- <el-table-column label="营业执照" align="center" prop="LICENSE" />
      <el-table-column label="统一社会信用码" align="center" prop="creditCode" />
      <el-table-column label="银行名称" align="center" prop="bankName" />
      <el-table-column label="银行卡账户名" align="center" prop="bankCardName" />
      <el-table-column label="银行卡卡号" align="center" prop="bankCardNo" /> -->
      <el-table-column label="备注信息" align="center" prop="DESCRIPTION" />
      <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="状态" align="center" prop="STATUS" />
      <!-- <el-table-column label="最后操作人" align="center" prop="OPERATOR" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['backendApi:store:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['backendApi:store:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改店铺对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="550px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="所属商户Id" prop="merchantId">
          <el-input v-model="form.merchantId" placeholder="请输入所属商户" />
        </el-form-item>
        <el-form-item label="店铺名称" prop="NAME">
          <el-input v-model="form.NAME" placeholder="请输入店铺名称" />
        </el-form-item>
        <!-- <el-form-item label="店铺二维码" prop="qrCode">
          <el-input v-model="form.qrCode" placeholder="请输入店铺二维码" />
        </el-form-item>
        <el-form-item label="店铺LOGO" prop="LOGO">
          <el-input v-model="form.LOGO" placeholder="请输入店铺LOGO" />
        </el-form-item> -->
        <el-form-item label="是否默认" prop="isDefault">
          <el-input v-model="form.isDefault" placeholder="请输入是否默认" />
        </el-form-item>
        <el-form-item label="联系人姓名" prop="CONTACT">
          <el-input v-model="form.CONTACT" placeholder="请输入联系人姓名" />
        </el-form-item>
        <el-form-item label="微信支付商户号" prop="wxMchId">
          <el-input v-model="form.wxMchId" placeholder="请输入微信支付商户号" />
        </el-form-item>
        <el-form-item label="微信支付APIv2密钥" prop="wxApiV2">
          <el-input v-model="form.wxApiV2" placeholder="请输入微信支付APIv2密钥" />
        </el-form-item>
        <el-form-item label="微信支付证书" prop="wxCertPath">
          <el-input v-model="form.wxCertPath" placeholder="请输入微信支付证书" />
        </el-form-item>
        <el-form-item label="支付宝appId" prop="alipayAppId">
          <el-input v-model="form.alipayAppId" placeholder="请输入支付宝appId" />
        </el-form-item>
        <el-form-item label="支付宝应用私钥" prop="alipayPrivateKey">
          <el-input v-model="form.alipayPrivateKey" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="支付宝应用公钥" prop="alipayPublicKey">
          <el-input v-model="form.alipayPublicKey" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="联系电话" prop="PHONE">
          <el-input v-model="form.PHONE" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="地址" prop="ADDRESS">
          <el-input v-model="form.ADDRESS" placeholder="请输入地址" />
        </el-form-item>
        <!-- <el-form-item label="经度" prop="LATITUDE">
          <el-input v-model="form.LATITUDE" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="维度" prop="LONGITUDE">
          <el-input v-model="form.LONGITUDE" placeholder="请输入维度" />
        </el-form-item>
        <el-form-item label="距离" prop="DISTANCE">
          <el-input v-model="form.DISTANCE" placeholder="请输入距离" />
        </el-form-item> -->
        <el-form-item label="营业时间" prop="HOURS">
          <el-input v-model="form.HOURS" placeholder="请输入营业时间" />
        </el-form-item>
        <!-- <el-form-item label="营业执照" prop="LICENSE">
          <el-input v-model="form.LICENSE" placeholder="请输入营业执照" />
        </el-form-item>
        <el-form-item label="统一社会信用码" prop="creditCode">
          <el-input v-model="form.creditCode" placeholder="请输入统一社会信用码" />
        </el-form-item> -->
        <el-form-item label="银行名称" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入银行名称" />
        </el-form-item>
        <el-form-item label="银行卡账户名" prop="bankCardName">
          <el-input v-model="form.bankCardName" placeholder="请输入银行卡账户名" />
        </el-form-item>
        <el-form-item label="银行卡卡号" prop="bankCardNo">
          <el-input v-model="form.bankCardNo" placeholder="请输入银行卡卡号" />
        </el-form-item>
        <el-form-item label="备注信息" prop="DESCRIPTION">
          <el-input v-model="form.DESCRIPTION" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="最后操作人" prop="OPERATOR">
          <el-input v-model="form.OPERATOR" placeholder="请输入最后操作人" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStore, getStore, delStore, addStore, updateStore } from "@/api/backendApi/store";

export default {
  name: "Store",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 店铺表格数据
      storeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        merchantId: null,
        NAME: null,
        qrCode: null,
        LOGO: null,
        isDefault: null,
        CONTACT: null,
        wxMchId: null,
        wxApiV2: null,
        wxCertPath: null,
        alipayAppId: null,
        alipayPrivateKey: null,
        alipayPublicKey: null,
        PHONE: null,
        ADDRESS: null,
        LATITUDE: null,
        LONGITUDE: null,
        DISTANCE: null,
        HOURS: null,
        LICENSE: null,
        creditCode: null,
        bankName: null,
        bankCardName: null,
        bankCardNo: null,
        DESCRIPTION: null,
        createTime: null,
        updateTime: null,
        STATUS: null,
        OPERATOR: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        NAME: [
          { required: true, message: "店铺名称不能为空", trigger: "blur" }
        ],
        isDefault: [
          { required: true, message: "是否默认不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询店铺列表 */
    getList() {
      this.loading = true;
      listStore(this.queryParams).then(response => {
        this.storeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ID: null,
        merchantId: null,
        NAME: null,
        qrCode: null,
        LOGO: null,
        isDefault: null,
        CONTACT: null,
        wxMchId: null,
        wxApiV2: null,
        wxCertPath: null,
        alipayAppId: null,
        alipayPrivateKey: null,
        alipayPublicKey: null,
        PHONE: null,
        ADDRESS: null,
        LATITUDE: null,
        LONGITUDE: null,
        DISTANCE: null,
        HOURS: null,
        LICENSE: null,
        creditCode: null,
        bankName: null,
        bankCardName: null,
        bankCardNo: null,
        DESCRIPTION: null,
        createTime: null,
        updateTime: null,
        STATUS: null,
        OPERATOR: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.ID)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加店铺";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ID = row.ID || this.ids
      getStore(ID).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改店铺";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ID != null) {
            updateStore(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStore(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const IDs = row.ID || this.ids;
      this.$modal.confirm('是否确认删除店铺编号为"' + IDs + '"的数据项？').then(function() {
        return delStore(IDs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('backendApi/store/export', {
        ...this.queryParams
      }, `store_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
